package com.lzy.mall.product.web.v2;

import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.product.entity.PmsCategory;
import com.lzy.mall.product.service.PmsCategoryService;
import com.lzy.mall.product.service.PmsSkuInfoService;
import com.lzy.mall.product.vo.SkuItemVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @author lzy
 * @date 2021/10/16 13:05
 */
@RestController
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
@RequestMapping("/v1")
public class IndexController {

    private final PmsCategoryService categoryService;

    @GetMapping({"/index"})
    public ResultUtils indexPage(){
        List<PmsCategory> list = categoryService.getLevel1();
        return ResultUtils.ok().setData(list);
    }

    @RequestMapping("/index/catalog.json")
    public String getCatelogJson() {
        String map = categoryService.getCatelogJson();
        return map;
    }


    private final PmsSkuInfoService skuInfoService;

    /**
     * 展示sku详情
     * @param skuId
     * @param model
     */
    @RequestMapping("/{skuId}.html")
    public SkuItemVo skuItem(@PathVariable("skuId") Long skuId){
        SkuItemVo vo = skuInfoService.item(skuId);
        return vo;
    }
}
